package com.fjnu.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.fjnu.dao.IBaseRepairDao;
import com.fjnu.dao.common.BaseDaoImpl;
import com.fjnu.dao.common.DaoException;
import com.fjnu.entities.BaseRepair;
import com.fjnu.entities.User;
@Repository
public class BaseRepairDao extends BaseDaoImpl<BaseRepair> implements IBaseRepairDao {

	public List<BaseRepair> findUserRepair(User user){
		String hql="from BaseRepair b where b.reportUser.idnumber=?";
		List<BaseRepair> list = findByHQL(hql,user.getIdnumber());
		if(list.size()==0){
			throw new DaoException("报修单为空");
		}
		return list;
	}
	
	public BaseRepair findUniqueRepair(int instrumentId) {
		String hql="from BaseRepair b where b.mainInstrument.id=?";
		List<BaseRepair> list = findByHQL(hql,instrumentId);
		if(list.size()==0){
			throw new DaoException("报修单为空");
		}
		return list.get(0);
	}

	
	public void updateRepair(String repairReason,Integer id) {
		String names[]={"repairReason"};
		partUpdate(id, names, repairReason,id);
	}

	
	public void addRepair(BaseRepair baseRepair) {
		save(baseRepair);
	}

	
}
